
//#pragma once
#include"graphics.h"

//**************************************机器算法


extern int count;
extern WINDOW* g_win;
extern GRAPHICS_COLOR g_fore_color;
extern GRAPHICS_COLOR g_back_color;
extern int g_style;

void computerStep(POINT* head )
{
	static int s[15][15]= {0};	//设置优先级
		
	bool flag;

	POINT* str1 = head->next;
	
	if( ( ( (str1->x)-7)/2 -1) > -1)		//设置人下的优先级
	{
		s[( (str1->x)-7)/2 -1][ (str1->y-10)/4 ] += 5;
		if( ( (str1->y-10)/4 +1) <15 )
			s[( (str1->x)-7)/2 -1][ (str1->y-10)/4 +1] += 5;
	}
		
	if( ( (str1->y-10)/4 -1) > -1)
	{
		s[( (str1->x)-7)/2 ][ (str1->y-10)/4 -1] += 5;	
		if( ( ( (str1->x)-7)/2 +1) <15 )
			s[( (str1->x)-7)/2 +1][ (str1->y-10)/4 -1] += 5;
	}
	if(( ( (str1->x)-7)/2 -1) > -1 &&  ( (str1->y-10)/4 -1) > -1 )
		s[( (str1->x)-7)/2 -1][ (str1->y-10)/4 -1] += 5;	
	if( ( ( (str1->x)-7)/2 +1) <15 )
	{
		s[( (str1->x)-7)/2 +1][ (str1->y-10)/4 ] += 5;
		if( ( (str1->y-10)/4) +1 <15)
			s[( (str1->x)-7)/2 +1][ (str1->y-10)/4 +1] += 5;
	}
	if( ( (str1->y-10)/4) +1 <15)
		s[( (str1->x)-7)/2 ][ (str1->y-10)/4 +1] += 5;
	
	
	if(head->next->next != NULL)
	{
		POINT* str2 = head->next->next;
		if( ( ( (str1->x)-7)/2 -1) > -1)		//设置机器下的优先级
		{
			s[( (str1->x)-7)/2 -1][ (str1->y-28)/4 ] += 15;
			if( ( (str1->y-28)/4 +1) <15 )
			s[( (str1->x)-7)/2 -1][ (str1->y-28)/4 +1] += 15;
		}
		
		if( ( (str1->y-28)/4 -1) > -1)
		{
			s[( (str1->x)-7)/2 ][ (str1->y-28)/4 -1] += 15;	
			if( ( ( (str1->x)-7)/2 +1) <15 )
				s[( (str1->x)-7)/2 +1][ (str1->y-28)/4 -1] += 15;
		}
		if(( ( (str1->x)-7)/2 -1) > -1 &&  ( (str1->y-28)/4 -1) > -1 )
			s[( (str1->x)-7)/2 -1][ (str1->y-28)/4 -1] += 15;	
		if( ( ( (str1->x)-7)/2 +1) <15 )
		{
			s[( (str1->x)-7)/2 +1][ (str1->y-28)/4 ] += 15;
			if( ( (str1->y-28)/4) +1 <15)
			s[( (str1->x)-7)/2 +1][ (str1->y-28)/4 +1] += 15;
		}
		if( ( (str1->y-28)/4) +1 <15)
			s[( (str1->x)-7)/2 ][ (str1->y-28)/4 +1] += 15;
	
	
	}	
		
		
		
		
		
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////	
//判断机器是否已成4粒	

	
	int i;
	int j;
	int n;
	POINT* p = NULL;
	POINT tmp1,tmp2; 
	POINT* tmp = NULL;
	if(head->next->next != NULL)
	{
		p = (head->next)->next;
	
		for(i=0; i<5; i++)		//判断电脑横轴4个
		{
			n=0;			//初始化
			tmp = p;		//初始化
			
			while(1)
			{

				if(tmp == NULL)
					break;
				if(tmp->x == p->x && (tmp->y) >= (p->y)+(i-4)*WIDTH && (tmp->y) <= (p->y)+i*WIDTH )
				{	
					n++;
				}
			
				tmp=tmp->next;
				if(tmp == NULL)
					break;
				tmp=tmp->next;	//两个子一回合
		
			}	
			
			if(n == 4 )
			{
				
				for(j=i-4; j<=i; j++)                                                                                                                                                                                                                                                                                       
				{
					flag = true;
					tmp1.x = p->x;
					tmp1.y = (p->y)+(j*WIDTH);
					for(tmp = head->next; tmp != NULL; tmp=tmp->next)
						if(tmp->x == p->x && tmp->y == (p->y)+(j*WIDTH) ||  (p->x) >=35 || (p->x) <= 7  ||  ( p->y )+(j*WIDTH) >= 66 || (p->y)+(j*WIDTH)  <= 10 )
							flag =false;
					if(flag)
					{
						addChess(tmp1,head);	//电脑下的棋子
						return;
					}
				}	
				
			}
		}
	}

	
	if(head->next->next != NULL)
	{
		p = (head->next)->next;
		for(i=0; i<5; i++)		//判断电脑竖轴4个
		{
			n=0;			//初始化
			tmp = p;		//初始化
			while(1)
			{
	
				if(tmp == NULL)
					break;
				if(tmp->y == p->y && (tmp->x) >= (p->x)+(i-4)*LENGTH && (tmp->x) <= (p->x)+i*LENGTH )
				{	
					n++;
				}
				
				tmp=tmp->next;
				if(tmp == NULL)
					break;
				tmp=tmp->next;	//两个子一回合
	
			}	
			if(n == 4 )
			{
				
				for(j=i-4; j<=i; j++)
				{
					flag = true;
					tmp1.x = p->x+(j*LENGTH);
					tmp1.y = (p->y);
					for(tmp = head->next; tmp != NULL; tmp=tmp->next)
						if(tmp->x == (p->x +(j*LENGTH) ) && tmp->y == (p->y) || (p->x)+(j*LENGTH) >=35 || (p->x)+(j*LENGTH) <= 7  ||  ( p->y ) >= 66 || (p->y)  <= 10 )
							flag =false;
					if(flag)
					{
						addChess(tmp1,head);	//电脑下的棋子
						return;
					}
				}	
				
			}
		}
	}
	

	
	
	if(head->next->next != NULL)
	{
		p = (head->next)->next;
		for(i=0; i<5; i++)		//判断电脑左斜轴4个
		{
			n=0;			//初始化
			tmp = p;		//初始化
			while(1)
			{

				if(tmp == NULL)
					break;
				if( (tmp->x == p->x+(i-4)*LENGTH && tmp->y == p->y+(i-4)*WIDTH) || (tmp->x == p->x+(i-3)*LENGTH && tmp->y == p->y+(i-3)*WIDTH) ||  (tmp->x == p->x+(i-2)*LENGTH && tmp->y == p->y+(i-2)*WIDTH) || (tmp->x == p->x+(i-1)*LENGTH && tmp->y == p->y+(i-1)*WIDTH) || (tmp->x == p->x+(i)*LENGTH && tmp->y == p->y+(i)*WIDTH))
				{
					n++;
				}
			
				tmp=tmp->next;
				if(tmp == NULL)
					break;
				tmp=tmp->next;	//两个子一回合
	
			}	
			
			
			if(n == 4 )
			{
				
				for(j=i-4; j<=i; j++)
				{
					flag = true;
					tmp1.x = (p->x)+(j*LENGTH);
					tmp1.y = (p->y)+(j*WIDTH);
					for(tmp = head->next; tmp != NULL; tmp=tmp->next)
						if(tmp->x == ( (p->x) +(j*LENGTH) ) && tmp->y == (p->y)+(j*WIDTH)||  (p->x)+(j*LENGTH) >=35 || (p->x)+(j*LENGTH) <= 7  ||  ( p->y )+(j*WIDTH) >= 66 || (p->y)+(j*WIDTH)  <= 10  )
							flag =false;
					if(flag)
					{
						addChess(tmp1,head);	//电脑下的棋子
						return;
					}
				}	
				
			}
		}
	}
	
	
	if(head->next->next != NULL)
	{
		p = (head->next)->next;
		for(i=0; i<5; i++)		//判断电脑右斜轴4粒
		{
			n=0;			//初始化
			tmp = p;		//初始化
			while(1)
			{
	
				if(tmp == NULL)
					break;
				if( (tmp->x == p->x+(i-4)*LENGTH && tmp->y == p->y+(4-i)*WIDTH) || (tmp->x == p->x+(i-3)*LENGTH && tmp->y == p->y+(3-i)*WIDTH) || (tmp->x == p->x+(i-2)*LENGTH && tmp->y == p->y+(2-i)*WIDTH) || (tmp->x == p->x+(i-1)*LENGTH && tmp->y == p->y+(1-i)*WIDTH) || (tmp->x == p->x+(i)*LENGTH && tmp->y == p->y+(-i)*WIDTH))
				{	
					n++;
				}
			
				tmp=tmp->next;
				if(tmp == NULL)
					break;
				tmp=tmp->next;	//两个子一回合
	
			}	

			if(n == 4 )
			{
				
				for(j=i-4; j<=i; j++)
				{
					flag = true;
					tmp1.x = (p->x)+(j*LENGTH);
					tmp1.y = (p->y)-(j*WIDTH);
					for(tmp = head->next; tmp != NULL; tmp=tmp->next)
						if(tmp->x == ( (p->x) +(j*LENGTH) ) && tmp->y == (p->y)-(j*WIDTH) ||  (p->x)+(j*LENGTH) >=35 || (p->x)+(j*LENGTH) <= 7  ||  ( p->y )-(j*WIDTH) >= 66 || (p->y)-(j*WIDTH)  <= 10 ) 
							flag =false;
					if(flag)
					{
						addChess(tmp1,head);	//电脑下的棋子
						return;
					}
				}	
				
			}
		}
	}
	
	

	
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////	
//判断人是否已成4粒
	
	
	
	p = head->next;
	for(i=0; i<5; i++)		//判断人横轴4个	
	{
		n=0;			//初始化
		tmp = p;		//初始化
		while(1)
		{

			if(tmp == NULL)
				break;
			if(tmp->x == p->x && (tmp->y) >= (p->y)+(i-4)*WIDTH && (tmp->y) <= (p->y)+i*WIDTH )
			{	
				n++;
			}
			
			tmp=tmp->next;
			if(tmp == NULL)
				break;
			tmp=tmp->next;	//两个子一回合
	
		}	

		if(n == 4 )
		{
				
			for(j=i-4; j<=i; j++)
			{
				flag = true;
				tmp1.x = p->x;
				tmp1.y = (p->y)+(j*WIDTH);
				for(tmp = head->next; tmp != NULL; tmp=tmp->next)
					if(tmp->x == p->x && tmp->y == (p->y)+(j*WIDTH) ||  p->x >=35 || p->x<=7  ||  ( p->y )+(j*WIDTH) >= 66 || (p->y)+(j*WIDTH)  <= 10 )
							flag =false;
				if(flag)
				{
					addChess(tmp1,head);	//电脑下的棋子
					return;
				}
			}	
				
		}
	}
	
	
	
	
	
	p = head->next;
	for(i=0; i<5; i++)		//判断人竖轴4个
	{
		n=0;			//初始化
		tmp = p;		//初始化
		while(1)
		{

			if(tmp == NULL)
				break;
			if(tmp->y == p->y && (tmp->x) >= (p->x)+(i-4)*LENGTH && (tmp->x) <= (p->x)+i*LENGTH )
			{	
				n++;
			}
			
			tmp=tmp->next;
			if(tmp == NULL)
				break;
			tmp=tmp->next;	//两个子一回合
	
		}	

		if(n == 4 )
		{
				
			for(j=i-4; j<=i; j++)
			{
				flag = true;
				tmp1.x = p->x+(j*LENGTH);
				tmp1.y = (p->y);
				for(tmp = head->next; tmp != NULL; tmp=tmp->next)
					if(tmp->x == p->x+(j*LENGTH) && tmp->y == (p->y) ||  p->x+(j*LENGTH) >=35 || p->x+(j*LENGTH)<=7  ||  ( p->y ) >= 66 || (p->y)  <= 10 ) 
							flag =false;
				if(flag)
				{
					addChess(tmp1,head);	//电脑下的棋子
					return;
				}
			}	
				
		}
	}
	



	p = head->next;
	for(i=0; i<5; i++)		//判断人左斜轴4个
	{
		n=0;			//初始化
		tmp = p;		//初始化
		while(1)
		{

			if(tmp == NULL)
				break;
			if((tmp->x == p->x+(i-4)*LENGTH && tmp->y == p->y+(i-4)*WIDTH) || (tmp->x == p->x+(i-3)*LENGTH && tmp->y == p->y+(i-3)*WIDTH) ||  (tmp->x == p->x+(i-2)*LENGTH && tmp->y == p->y+(i-2)*WIDTH) || (tmp->x == p->x+(i-1)*LENGTH && tmp->y == p->y+(i-1)*WIDTH) || (tmp->x == p->x+(i)*LENGTH && tmp->y == p->y+(i)*WIDTH))
			{
				n++;
			}
			
			tmp=tmp->next;
			if(tmp == NULL)
				break;
			tmp=tmp->next;	//两个子一回合
	
		}	
		/*char pp[10],qq[10];
			pp[0]='0'+i;
			pp[1]='\0';
			qq[0]=n+'0';
			qq[1]='\0';
			mvaddstr(4,0,pp);
			mvaddstr(5,0,qq);
			wrefresh(g_win);				//刷新窗口，显示窗口的最新变化
			sleep(1);
		*/		
	
		if(n == 4 )
		{	

			for(j=i-4; j<=i; j++)
			{
				flag = true;
				tmp1.x = (p->x)+(j*LENGTH);
				tmp1.y = (p->y)+(j*WIDTH);
				for(tmp = head->next; tmp != NULL; tmp=tmp->next)
					if(tmp->x == p->x+(j*LENGTH) && tmp->y == (p->y) +(j*WIDTH)||  p->x+(j*LENGTH) >=35 || p->x+(j*LENGTH)<=7  || (p->y)+(j*WIDTH) >= 66 || (p->y)+(j*WIDTH)  <= 10 ) 
							flag =false;
				if(flag)
				{
					addChess(tmp1,head);	//电脑下的棋子
					return;
				}
			}	
				
		}
	}
	
	
	p = head->next;
	for(i=0; i<5; i++)		//判断人右斜轴4粒
	{
		n=0;			//初始化
		tmp = p;		//初始化
		while(1)
		{

			if(tmp == NULL)
				break;
			if( (tmp->x == p->x+(i-4)*LENGTH && tmp->y == p->y+(4-i)*WIDTH) || (tmp->x == p->x+(i-3)*LENGTH && tmp->y == p->y+(3-i)*WIDTH) || (tmp->x == p->x+(i-2)*LENGTH && tmp->y == p->y+(2-i)*WIDTH) || (tmp->x == p->x+(i-1)*LENGTH && tmp->y == p->y+(1-i)*WIDTH) || (tmp->x == p->x+(i)*LENGTH && tmp->y == p->y+(-i)*WIDTH))
			{	
				n++;
			}
			
			tmp=tmp->next;
			if(tmp == NULL)
				break;
			tmp=tmp->next;	//两个子一回合
	
		}	

	
		if(n == 4 )
		{
				
			for(j=i-4; j<=i; j++)
			{
				flag = true;
				tmp1.x = p->x+(j*LENGTH);
				tmp1.y = (p->y)-(j*WIDTH);
				for(tmp = head->next; tmp != NULL; tmp=tmp->next)
					if(tmp->x == p->x+(j*LENGTH) && tmp->y == (p->y)-(j*WIDTH) ||  p->x+(j*LENGTH) >=35 || p->x+(j*LENGTH)<=7  || (p->y)-(j*WIDTH) >= 66 || (p->y)-(j*WIDTH)  <= 10 ) 
							flag =false;
				if(flag)
				{
					addChess(tmp1,head);	//电脑下的棋子
					return;
				}
			}	
				
		}
	}






////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//判断电脑3粒


	p = (head->next)->next;
	if(head->next->next != NULL)
	{
		p = (head->next)->next;
	
		for(i=0; i<4; i++)		//判断电脑横轴3个
		{
			n=0;			//初始化
			tmp = p;		//初始化
			
			while(1)
			{

				if(tmp == NULL)
					break;
				if(tmp->x == p->x && (tmp->y) >= (p->y)+(i-3)*WIDTH && (tmp->y) <= (p->y)+i*WIDTH )
				{	
					n++;
				}
			
				tmp=tmp->next;
				if(tmp == NULL)
					break;
				tmp=tmp->next;	//两个子一回合
		
			}	
			
			if(n == 3 )
			{
				
				for(j=i-3; j<=i; j++)
				{
					flag = true;
					tmp1.x = p->x;
					tmp1.y = (p->y)+(j*WIDTH);
					for(tmp = head->next; tmp != NULL; tmp=tmp->next)
						if(tmp->x == p->x && tmp->y == (p->y)+(j*WIDTH) ||  (p->x) >=35 || (p->x) <= 7  ||  ( p->y )+(j*WIDTH) >= 66 || (p->y)+(j*WIDTH)  <= 10  )
							flag =false;
					if(flag)
					{
						addChess(tmp1,head);	//电脑下的棋子
						return;
					}
				}	
				
			}
		}
	}

	
	
	if(head->next->next != NULL)
	{
		p = (head->next)->next;
		for(i=0; i<4; i++)		//判断电脑竖轴3个
		{
			n=0;			//初始化
			tmp = p;		//初始化
			while(1)
			{
	
				if(tmp == NULL)
					break;
				if(tmp->y == p->y && (tmp->x) >= (p->x)+(i-3)*LENGTH && (tmp->x) <= (p->x)+i*LENGTH )
				{	
					n++;
				}
				
				tmp=tmp->next;
				if(tmp == NULL)
					break;
				tmp=tmp->next;	//两个子一回合
	
			}	
			if(n == 3 )
			{
				
				for(j=i-3; j<=i; j++)
				{
					flag = true;
					tmp1.x = p->x+(j*LENGTH);
					tmp1.y = (p->y);
					for(tmp = head->next; tmp != NULL; tmp=tmp->next)
						if(tmp->x == (p->x +(j*LENGTH) ) && tmp->y == (p->y) || (p->x)+(j*LENGTH) >=35 || (p->x)+(j*LENGTH) <= 7  ||  ( p->y ) >= 66 || (p->y)  <= 10 )
							flag =false;
					if(flag)
					{
						addChess(tmp1,head);	//电脑下的棋子
						return;
					}
				}	
				
			}
		}
	}
	
	
	
	
	
	
	if(head->next->next != NULL)
	{
		p = (head->next)->next;
		for(i=0; i<4; i++)		//判断电脑左斜轴3个
		{
			n=0;			//初始化
			tmp = p;		//初始化
			while(1)
			{

				if(tmp == NULL)
					break;
				if( (tmp->x == p->x+(i-3)*LENGTH && tmp->y == p->y+(i-3)*WIDTH) ||  (tmp->x == p->x+(i-2)*LENGTH && tmp->y == p->y+(i-2)*WIDTH) || (tmp->x == p->x+(i-1)*LENGTH && tmp->y == p->y+(i-1)*WIDTH) || (tmp->x == p->x+(i)*LENGTH && tmp->y == p->y+(i)*WIDTH))
				{
					n++;
				}
			
				tmp=tmp->next;
				if(tmp == NULL)
					break;
				tmp=tmp->next;	//两个子一回合
	
			}	
			
			
			if(n == 3 )
			{
				
				for(j=i-3; j<=i; j++)
				{
					flag = true;
					tmp1.x = (p->x)+(j*LENGTH);
					tmp1.y = (p->y)+(j*WIDTH);
					for(tmp = head->next; tmp != NULL; tmp=tmp->next)
						if(tmp->x == ( (p->x) +(j*LENGTH) ) && tmp->y == (p->y)+(j*WIDTH)||  (p->x)+(j*LENGTH) >=35 || (p->x)+(j*LENGTH) <= 7  ||  ( p->y )+(j*WIDTH) >= 66|| (p->y)+(j*WIDTH)  <= 10  )
							flag =false;
					if(flag)
					{
						addChess(tmp1,head);	//电脑下的棋子
						return;
					}
				}	
				
			}
		}
	}
	

	
	
	
	if(head->next->next != NULL)
	{
		p = (head->next)->next;
		for(i=0; i<4; i++)		//判断电脑右斜轴4粒
		{
			n=0;			//初始化
			tmp = p;		//初始化
			while(1)
			{
	
				if(tmp == NULL)
					break;
				if( (tmp->x == p->x+(i-3)*LENGTH && tmp->y == p->y+(3-i)*WIDTH) || (tmp->x == p->x+(i-2)*LENGTH && tmp->y == p->y+(2-i)*WIDTH) || (tmp->x == p->x+(i-1)*LENGTH && tmp->y == p->y+(1-i)*WIDTH) || (tmp->x == p->x+(i)*LENGTH && tmp->y == p->y+(-i)*WIDTH))
				{	
					n++;
				}
			
				tmp=tmp->next;
				if(tmp == NULL)
					break;
				tmp=tmp->next;	//两个子一回合
	
			}	

			if(n == 3 )
			{
				
				for(j=i-3; j<=i; j++)
				{
					flag = true;
					tmp1.x = (p->x)+(j*LENGTH);
					tmp1.y = (p->y)-(j*WIDTH);
					for(tmp = head->next; tmp != NULL; tmp=tmp->next)
						if(tmp->x == ( (p->x) +(j*LENGTH) ) && tmp->y == (p->y)-(j*WIDTH) ||  (p->x)+(j*LENGTH) >=35 || (p->x)+(j*LENGTH) <= 7  ||  ( p->y )-(j*WIDTH) >= 66 || (p->y)-(j*WIDTH)  <= 10 ) 
							flag =false;
					if(flag)
					{
						addChess(tmp1,head);	//电脑下的棋子
						return;
					}
				}	
				
			}
		}
	}
	
	
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//判断人3粒


	p = head->next;
	for(i=0; i<4; i++)		//判断人横轴3个	
	{
		n=0;			//初始化
		tmp = p;		//初始化
		while(1)
		{

			if(tmp == NULL)
				break;
			if(tmp->x == p->x && (tmp->y) >= (p->y)+(i-3)*WIDTH && (tmp->y) <= (p->y)+i*WIDTH )
			{	
				n++;
			}
			
			tmp=tmp->next;
			if(tmp == NULL)
				break;
			tmp=tmp->next;	//两个子一回合
	
		}	

		if(n == 3 )
		{
				
			for(j=i-3; j<=i; j++)
			{
				flag = true;
				tmp1.x = p->x;
				tmp1.y = (p->y)+(j*WIDTH);
				for(tmp = head->next; tmp != NULL; tmp=tmp->next)
					if(tmp->x == p->x && tmp->y == (p->y)+(j*WIDTH) ||  p->x >=35 || p->x<=7  ||  ( p->y )+(j*WIDTH) >= 66 || (p->y)+(j*WIDTH)  <= 10 )
							flag =false;
				if(flag)
				{
					addChess(tmp1,head);	//电脑下的棋子
					return;
				}
			}	
				
		}
	}
	
		
	
	
	
	p = head->next;
	for(i=0; i<4; i++)		//判断人竖轴3个
	{
		n=0;			//初始化
		tmp = p;		//初始化
		while(1)
		{

			if(tmp == NULL)
				break;
			if(tmp->y == p->y && (tmp->x) >= (p->x)+(i-4)*LENGTH && (tmp->x) <= (p->x)+i*LENGTH )
			{	
				n++;
			}
			
			tmp=tmp->next;
			if(tmp == NULL)
				break;
			tmp=tmp->next;	//两个子一回合
	
		}	

		if(n == 3 )
		{
				
			for(j=i-3; j<=i; j++)
			{
				flag = true;
				tmp1.x = p->x+(j*LENGTH);
				tmp1.y = (p->y);
				for(tmp = head->next; tmp != NULL; tmp=tmp->next)
					if(tmp->x == p->x+(j*LENGTH) && tmp->y == (p->y) ||  p->x+(j*LENGTH) >=35 || p->x+(j*LENGTH)<=7  ||  ( p->y ) >= 66 || (p->y)  <= 10 ) 
							flag =false;
				if(flag)
				{
					addChess(tmp1,head);	//电脑下的棋子
					return;
				}
			}	
				
		}
	}
	
	


	
	p = head->next;
	for(i=0; i<4; i++)		//判断人向左斜轴3个
	{
		n=0;			//初始化
		tmp = p;		//初始化
		while(1)
		{

			if(tmp == NULL)
				break;
			if( (tmp->x == p->x+(i-3)*LENGTH && tmp->y == p->y+(i-3)*WIDTH) ||  (tmp->x == p->x+(i-2)*LENGTH && tmp->y == p->y+(i-2)*WIDTH) || (tmp->x == p->x+(i-1)*LENGTH && tmp->y == p->y+(i-1)*WIDTH) || (tmp->x == p->x+(i)*LENGTH && tmp->y == p->y+(i)*WIDTH))
			{
				n++;
			}
			
			tmp=tmp->next;
			if(tmp == NULL)
				break;
			tmp=tmp->next;	//两个子一回合
	
		}	
		
	
		if(n == 3 )
		{	

			for(j=i-3; j<=i; j++)
			{
				flag = true;
				tmp1.x = (p->x)+(j*LENGTH);
				tmp1.y = (p->y)+(j*WIDTH);
				for(tmp = head->next; tmp != NULL; tmp=tmp->next)
					if(tmp->x == p->x+(j*LENGTH) && tmp->y == (p->y) +(j*WIDTH)||  p->x+(j*LENGTH) >=35 || p->x+(j*LENGTH)<=7  || (p->y)+(j*WIDTH) >= 66 || (p->y)+(j*WIDTH)  <= 10 ) 
							flag =false;
				if(flag)
				{
					addChess(tmp1,head);	//电脑下的棋子
					return;
				}
			}	
				
		}
	}	
	
	
	
	
	
	p = head->next;
	for(i=0; i<4; i++)		//判断人右斜轴3粒
	{
		n=0;			//初始化
		tmp = p;		//初始化
		while(1)
		{

			if(tmp == NULL)
				break;
			if(  (tmp->x == p->x+(i-3)*LENGTH && tmp->y == p->y+(3-i)*WIDTH) || (tmp->x == p->x+(i-2)*LENGTH && tmp->y == p->y+(2-i)*WIDTH) || (tmp->x == p->x+(i-1)*LENGTH && tmp->y == p->y+(1-i)*WIDTH) || (tmp->x == p->x+(i)*LENGTH && tmp->y == p->y+(-i)*WIDTH))
			{	
				n++;
			}
			
			tmp=tmp->next;
			if(tmp == NULL)
				break;
			tmp=tmp->next;	//两个子一回合
	
		}	

	
		if(n == 3 )
		{
				
			for(j=i-3; j<=i; j++)
			{
				flag = true;
				tmp1.x = p->x+(j*LENGTH);
				tmp1.y = (p->y)-(j*WIDTH);
				for(tmp = head->next; tmp != NULL; tmp=tmp->next)
					if(tmp->x == p->x+(j*LENGTH) && tmp->y == (p->y)-(j*WIDTH) ||  p->x+(j*LENGTH) >=35 || p->x+(j*LENGTH)<=7  || (p->y)-(j*WIDTH) >= 66|| (p->y)-(j*WIDTH)  <= 10 ) 
							flag =false;
				if(flag)
				{
					addChess(tmp1,head);	//电脑下的棋子
					return;
				}
			}	
				
		}
	}
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//没有3粒或4粒
//优先级最高的优先	

	int maxX=0;
	int maxY=0;
	int max;
	max = s[0][0];
	for(i=0; i <15; i++)
		for(j=0; j<15; j++)
		{
			flag = true;
			str1=head;
			for( ; str1->next != NULL; str1 = str1->next)
				if( (str1->next->x-7)/2 == i && (str1->next->y-10)/4 ==j)
				{	
					flag = false;
					break;
				}
			if(flag && s[i][j] >= max)
			{	
		
					maxX = i;
					maxY = j;
					max = s[i][j];
			}
		}
	tmp1.x = 7 + maxX*2;
	tmp1.y = 10 + maxY*4;
	addChess(tmp1,head);
	return;

}
